#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=510,MAXM=4e3+10;
int n,m,w[MAXN],c[MAXN],d[MAXN],head[MAXN],cnt,rt,sum,sumch[MAXN],f[MAXN],pre[MAXN],tim,ed[MAXN],ans;
bool vis[MAXN];
struct edge
{
	int v,next;
}e[MAXN<<1];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
void getrt(int u,int fa)
{
	sumch[u]=1;
	f[u]=0;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(v==fa||vis[v])continue;
		getrt(v,u);
		sumch[u]+=sumch[v];
		f[u]=max(f[u],sumch[v]);
	}
	f[u]=max(f[u],sum-sumch[u]);
	if(f[u]<f[rt])rt=u;
	return;
}
void dfs(int u,int fa)
{
	pre[++tim]=u;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(v==fa||vis[v])continue;
		dfs(v,u);
	}
	ed[u]=tim;
	return;
}
void cal()
{
	tim=0;dfs(rt,0);
	int f[MAXN][MAXM],q[MAXM];
	for(int i=1;i<=ed[rt]+1;++i)
		for(int j=0;j<=m;++j)
			f[i][j]=-INF;
	f[1][0]=0;
	for(int i=1;i<=ed[rt];++i)
	{
		int u=pre[i];
		for(int j=0;j<c[u];++j)
			for(int k=j,l=1,r=0;k<=m;k+=c[u])
			{
				while(l<=r&&k-q[l]>c[u]*d[u])++l;
				if(l<=r)f[i+1][k]=max(f[i+1][k],f[i][q[l]]+(k-q[l])/c[u]*w[u]);
				while(l<=r&&f[i][k]>=f[i][q[r]]+(k-q[r])/c[u]*w[u])--r;
				q[++r]=k;
			}
		for(int j=0;j<=m;++j)f[ed[u]+1][j]=max(f[ed[u]+1][j],f[i][j]);
	}
	for(int i=0;i<=m;++i)ans=max(ans,f[ed[rt]+1][i]);
	return;
}
void solve()
{
	cal();
	vis[rt]=true;
	for(int i=head[rt];i;i=e[i].next)
	{
		int v=e[i].v;
		if(vis[v])continue;
		rt=0;
		sum=sumch[v];
		getrt(v,0);
		solve();
	}
	return;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int T=read();
	while(T--)
	{
		n=read();m=read();
		memset(head,0,sizeof(head));
		memset(vis,0,sizeof(vis));
		rt=cnt=ans=0;
		for(int i=1;i<=n;++i)w[i]=read();
		for(int i=1;i<=n;++i)c[i]=read();
		for(int i=1;i<=n;++i)d[i]=read();
		for(int i=1;i<n;++i)
		{
			int x=read(),y=read();
			addedge(x,y);addedge(y,x);
		}
		f[0]=INF;
		sum=n;
		getrt(1,0);
		solve();
		printf("%d\n",ans);
	}
	return 0;
}
